package br.ufu.si.view;

import java.awt.Component;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JToggleButton;
import javax.swing.text.JTextComponent;

public class ComponentUtil {

	public static void limparComponente(Component component) {
		if (component instanceof JTextComponent) {

			((JTextComponent) component).setText("");

		} else if (component instanceof JToggleButton) {
			
			((JToggleButton) component).setSelected(false);
			
		}
	}

	public static void limparComponentes(Component[] components) {
		for (Component component : components) {
			limparComponente(component);
		}
	}

	public static void habilitarComponentes(Component[] components, boolean habilitar) {
		for (Component component : components) {
			component.setEnabled(habilitar);
		}
	}
	
	public static <T> void popularCombo(List<T> itens, JComboBox<T> combo){
		combo.removeAllItems();
		for(T item:itens){
			combo.addItem(item);
		}
	}
	
	public static void popularCombo(Object[] itens, JComboBox<Object> combo){
		combo.removeAllItems();
		for(Object item:itens){
			combo.addItem(item);
		}
	}

}
